Nothing.
setEditable()
Method
Nothing happens because the lower text field does not have a registered listener.
You could modify the program so it has a listener,
but this would not follow the original design for the program.
A better idea (for this program) is to prevent the user from entering text
into the wrong text field.
This can be done with the setEditable()
method:
outText.setEditable( false );
Here outText
is a variable that refers to a JTextField
.
The setEditable()
method has one Boolean parameter.
If the parameter is false, then the user cannot type into the field.
However, the setText()
method still works, so the program can
use the field to display results.
Here is an excerpt from the program:
public class Repeater extends JFrame implements ActionListener { JLabel inLabel = new JLabel( "Enter Your Name: " ) ; JTextField inText = new JTextField( 15 ); JLabel outLabel = new JLabel( "Here is Your Name :" ) ; JTextField outText = new JTextField( 15 ); public Repeater( String title) // constructor { super( title ); setLayout( new FlowLayout() ); add( inLabel ) ; add( inText ) ; add( outLabel ) ; add( outText ) ; inText.addActionListener( this ); setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE ); } ..... }
Suggest a place to use the setEditable()
method.